﻿<style>
    .useritem {
    }

    .userinfo {
    }
</style>

<from class="layui-form layui-form-pane" action="">
    <input type="hidden" name="id">
    <div class="layui-form-item">
        <label class="layui-form-label">邀请地址</label>
        <div class="layui-input-block">
            <input type="text" id="url" autocomplete="off"
                   placeholder="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item" pane>
        <label class="layui-form-label">项目成员</label>
        <div class="layui-input-block">
            <table lay-filter="userlist">
                <thead>
                <tr>
                    <th lay-data="{field:'username', width:64}"></th>
                    <th lay-data="{field:'experience', width:100, sort:true}">姓名</th>
                    <th lay-data="{field:'sign'}">邮箱</th>
                    <th lay-data="{field:'action'}"></th>
                </tr>
                </thead>
                <tbody id="userlist">
                </tbody>
            </table>
        </div>
    </div>
</from>
<script type="text/javascript">
    layui.define(['layer', 'form'], function (exports) {
        var form = layui.form;
        form.render(); //这个很重要
    });

    function deleteuser(id) {
        workUtils.ajaxPost('../project/deleteuser', {
            userId: id,
            projectId: workUtils.get("id")
        }, function (result) {
            workUtils.msg(result,function () {
                loadUserList();
            });
        }, "确定移除该用户吗?");
    }

    function getContextPath() {
        var protocol = window.location.protocol;
        var host = window.location.host;
        var pathName = document.location.pathname;
        var index = pathName.substr(1).indexOf("/");
        var result = pathName.substr(0, index + 1);
        return protocol + "//" + host + result;
    }

    function loadUserList() {
        var id = workUtils.get("id");
        workUtils.ajaxGet("../project/projectuser/", {projectId: id}, function (data) {
            var html = '';
            for (var i = 0; i < data.length; i++) {
                var item = data[i];
                html += "<tr>";
                html += '<td class="userphoto" ><img src="../photo/get/' + item.user.id + '"  class="layui-nav-img user-photo" style="width: 32px;height: 32px;"></td>';
                html += '<td class="userinfo" >' + item.user.name + '</td>';
                html += '<td class="userinfo" >' + item.user.email + '</td>';
                html += '<td class="" ><a onclick="deleteuser('+item.user.id+');" class="layui-btn layui-btn-xs deleteuser" >移除</a></td>';
                html += "</tr>";
            }
            $("#userlist").html(html);
            //转换静态表格
            table.init('userlist', {
                height: 315 //设置高度
                , limit: 1000 //注意：请务必确保 limit 参数（默认：10）是与你服务端限定的数据条数一致
            });
        });

    }

    function initData(id) {
        var id = workUtils.get("id");
        $.getJSON("../project/get/" + id, function (data) {
            $("#url").val(getContextPath() + "/project/join/" + data.encodeId);
        });
        loadUserList();
    }
    $(document).ready(function () {
        initData();
    });
</script>